package com.hxut.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class C3p0Utils {

    //初始化数据源为空
    public static DataSource ds = null;
    static {
        //获取c3p0-config.xml中配置的数据源
        //ds = new ComboPooledDataSource();
        ds = new ComboPooledDataSource("mysql8");
    }

    public static DataSource getDataSource(){
        return ds;
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }

    public static void main(String[] args) throws SQLException {
        System.out.println("数据源=>"+getDataSource());
        System.out.println("连接=>"+getConnection());
    }
}
